from pyhive import hive

if __name__ == '__main__':
    # 远程安装依赖包
    # yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel gcc make gcc-c++ python-devel cyrus-sasl-devel cyrus-sasl-plain cyrus-sasl-gssapi -y
    # conda activate 对应环境
    # pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyhive pymysql sasl thrift thrift_sasl

    # 获取到Hive（Spark ThriftServer的连接）
    conn = hive.Connection(host="11.50.138.179", port=10000, username="hdfs")

    # 获取一个游标对象
    cursor = conn.cursor()

    # 执行sql
    cursor.execute("show tables")

    # 通过fetchall API获取返回值
    result = cursor.fetchall()
    print(result)
